package com.jiyi.activity.design;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.ImageView;

import com.swift.base.ActivityBase;
import com.swift.maintenance.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CoorDinatorActivity extends ActivityBase {

    @BindView(R.id.ivHead)
    ImageView ivHead;
    @BindView(R.id.tbMain)
    Toolbar tbMain;
    @BindView(R.id.tlMain)
    TabLayout tlMain;
    @BindView(R.id.vpMain)
    ViewPager vpMain;

    String[] tabTitle = new String[]{"aaa","bbb","ccc","ddd","eee","fff"};
    ArrayList<Fragment> tabFragment = new ArrayList<>();




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coor_dinator);
        ButterKnife.bind(this);

        initTab();

    }

    protected void initTab()
    {
        for(int i = 0;i<tabTitle.length;i++)
        {
            Log.e(TAG, "onCreate: "+tabTitle[i].toString());
            Fragment fragment = new TabFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("position",i);
            fragment.setArguments(bundle);
            tabFragment.add(fragment);
        }
        vpMain.setAdapter(fpa);

        tlMain.setupWithViewPager(vpMain);
    }

    private FragmentPagerAdapter fpa = new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            return tabFragment.get(position);
        }

        @Override
        public int getCount() {
            return tabFragment.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tabTitle[position];
        }
    };


}
